<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">
	*{
		margin:0;
		padding:0;
	}
	#suggest{
		width:382px;
		border:1px solid black;
		display:none;
		margin-bottom:10px;
	}
</style>
<script type="text/javascript" src="/jquery-1.8.3.js"></script>
<script>
	/* var xhr;
	function createXHR(){
		try{
			return new XMLHttpRequest();
		}catch(e){
			return new ActiveXObject("Microsoft.HTTPXML");
		}
	}
	function searchOnly(){
		var keyword=document.getElementById("keyword").value;
		xhr=createXHR();
		xhr.onreadystatechange=callback;
		xhr.open("POST","SearchNewsOne",true);
		xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xhr.send("keyword="+keyword);
	}
	function callback(){
		if(xhr.readyState==4 && xhr.status==200){
			var sobj=document.getElementById("suggest");
			sobj.innerHTML="";
			var arr=xhr.responseText.split(",");
			var suggest="";
			if(arr.length>0&&arr[0].length>0){
				for(var i=0;i<arr.length;i++){
					suggest+="<div onmouseover='suggestOver(this)' onmouseout='suggestOut(this)' onclick='setSearch(this)'>";
					suggest+=arr[i];
					suggest+="</div>";
				}
				sobj.innerHTML=suggest;
				document.getElementById("suggest").style.display="block";
				
			}else{
				document.getElementById("suggest").style.display="none";
			}
			
		}
		
	} */
	$(function(){
		$("#keyword").keyup(function(){
			$.post("SearchNewsOne",{keyword:$("#keyword").val()},callback)
		})
	})
	function callback(data){
		$("#suggest").html("");
		var arr=data.split(",");
		var suggest="";
		if(arr.length>0 &&arr[0].length>0){
			for(var i=0;i<arr.length;i++){
				suggest+=suggest+="<div onmouseover='suggestOver(this)' onmouseout='suggestOut(this)' onclick='setSearch(this)'>";
				suggest+=arr[i];
				suggest+="</div>";
			}
			$("#suggest").html(suggest);
			$("#suggest").css("display","block");
		}else{
			$("#suggest").css("display","none");
		}
	}
		function suggestOver(obj){
			$(obj).css("background","gray");
			$(obj).css("cursor","pointer");
		}
		function suggestOut(obj){
			$(obj).css("background","");
		}
		function setSearch(obj){
			var n_title=$(obj).html();
			$("#keyword").val(n_title);
			$("#suggest").css("display","none");
		}
	/* function suggestOver(obj){
		obj.style.background="gray";
		obj.style.cursor="pointer";
	}
	function suggestOut(obj){
		obj.style.background="";
	}
	function setSearch(obj){
		document.getElementById("keyword").value=obj.innerHTML;
		document.getElementById("suggest").style.display="none";
	} */
</script>
</head>
<body background="pic/ManBgroud.gif">
	<div>
		<input type="text" id="keyword" name="newsName" size="50px"/><input type="button" value="查找"/>
		<div id="suggest"></div>
		<table width=100% border=1px cellpadding=0 cellspacing=0>
			<tr>
				<th>新闻编号</th>
				<th>新闻标题</th>
				<th>新闻内容</th>
				<th>新闻时间</th>
				<th>所属板块</th>
				<th>发布人</th>
			</tr>
			<c:if test="${not empty sessionScope.newsList }">
				<c:forEach items="${newsList }" var="nl">
					<tr>
						<td>${nl.n_id }</td>
						<td>${nl.n_title }</td>
						<td width=30%>${nl.n_context }</td>
						<td>${nl.n_date }</td>
						<td>${nl.board.b_name }</td>
						<td>${nl.admin.a_name }</td>
					</tr>
				</c:forEach>
			
			</c:if>
		<tr>
			<td colspan="6" align="center">
				<a href="SearchNewsByPages?pageIndex=1">首页</a>&nbsp;&nbsp;&nbsp;
				<a href="SearchNewsByPages?pageIndex=${sessionScope.currPage-1 }">上一页</a>&nbsp;&nbsp;&nbsp;
				<a href="SearchNewsByPages?pageIndex=${sessionScope.currPage+1 }">下一页</a>&nbsp;&nbsp;&nbsp;
				<a href="SearchNewsByPages?pageIndex=${sessionScope.totalPages }">尾页</a>
			</td>
		</tr>
		</table>
	
	</div>

</body>
</html>